﻿<%@ Page Language="C#" AutoEventWireup="true" CodeFile="ChoiceOrgPers_List.aspx.cs" Inherits="Common_ChoiceOrgPers_List" %>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>显示人员</title>
    <link href="../CSS/css.CSS" type="text/css" rel="stylesheet" />
    <script language ="javascript" type ="text/javascript" >
    function ChoicePer(obj)
    {        
        //ID的集合
        var sPersIDInfo   = parent.RightFrameDown.form1.PersIDInfo.value;    
        var sPersNameInfo = parent.RightFrameDown.form1.PersNameInfo.value;
        
        var sBack = "";
        if(obj.checked)
        {
           sBack = DelRepeatData(sPersIDInfo,sPersNameInfo,obj.value,"1");
        }
        else
        {
           sBack = DelRepeatData(sPersIDInfo,sPersNameInfo,obj.value,"0");
        }
        
        var aBack = sBack.split('|');
        
        parent.RightFrameDown.form1.PersIDInfo.value   = aBack[0];
        parent.RightFrameDown.form1.POPIDCol.value     = parent.RightFrameDown.form1.OrgIDInfo.value +"^"+ aBack[0] ;
        
        parent.RightFrameDown.form1.PersNameInfo.value = aBack[1];
        parent.RightFrameDown.form1.POPNameCol.value   = parent.RightFrameDown.form1.OrgNameInfo.value +"^"+ aBack[1] ; 
        
//	     var sDelPersID   ="";  //人员ID 
//        var sDelPersID2   ="";  //人员ID 
//	    var sDelPersName = "";  //人员名称
//	    var sDelPersName2 = "";  //人员名称
//	    
//        var aPers = obj.value.split(',');
//        if(parent.RightFrameDown.form1.PersIDInfo.value != "")
//        {
//            var astr = parent.RightFrameDown.form1.PersIDInfo.value.split(',');
//            if(astr.length=="1")
//            {
//                var sDelPersID   = aPers[0];  //人员ID 	        
//	            var sDelPersName = aPers[1];  //人员名称
//            }
//            else
//            {
//                var sDelPersID   = "," + aPers[0];  //人员ID 	        
//	            var sDelPersID2   = aPers[0] + ",";  //人员ID 
//	            var sDelPersName = "," + aPers[1];  //人员名称
//	            var sDelPersName2 = aPers[1] + ",";  //人员名称
//	        }
//	        
//	        var sPersID   = "," + aPers[0];  //人员ID 
//	        var sPersName = "," + aPers[1];  //人员名称
//        }
//        else
//        {
//            var sPersID   = aPers[0];  //人员ID 
//	        var sPersName = aPers[1];  //人员名称
//	        var sDelPersID   = aPers[0];  //人员ID 
//	        var sDelPersName = aPers[1];  //人员名称
//        }
//        //debugger;
//        if(obj.checked)
//        {
//           parent.RightFrameDown.form1.PersIDInfo.value = parent.RightFrameDown.form1.PersIDInfo.value.replace(sDelPersID,"");
//           parent.RightFrameDown.form1.PersIDInfo.value = parent.RightFrameDown.form1.PersIDInfo.value.replace(sDelPersID2,"");
//           parent.RightFrameDown.form1.PersIDInfo.value = parent.RightFrameDown.form1.PersIDInfo.value + sPersID ;
//           parent.RightFrameDown.form1.PersNameInfo.value = parent.RightFrameDown.form1.PersNameInfo.value.replace(sDelPersName,"");
//           parent.RightFrameDown.form1.PersNameInfo.value = parent.RightFrameDown.form1.PersNameInfo.value.replace(sDelPersName2,"");
//           parent.RightFrameDown.form1.PersNameInfo.value = parent.RightFrameDown.form1.PersNameInfo.value + sPersName ;
//        }
//        else
//        {
//            parent.RightFrameDown.form1.PersIDInfo.value   = parent.RightFrameDown.form1.PersIDInfo.value.replace(sDelPersID,"");
//            parent.RightFrameDown.form1.PersIDInfo.value   = parent.RightFrameDown.form1.PersIDInfo.value.replace(sDelPersID2,"");
//            parent.RightFrameDown.form1.PersNameInfo.value = parent.RightFrameDown.form1.PersNameInfo.value.replace(sDelPersName,"");
//            parent.RightFrameDown.form1.PersNameInfo.value = parent.RightFrameDown.form1.PersNameInfo.value.replace(sDelPersName2,"");
//        }        
//        parent.RightFrameDown.form1.POPIDCol.value = parent.RightFrameDown.form1.OrgIDInfo.value +"^"+ parent.RightFrameDown.form1.PersIDInfo.value;
//        parent.RightFrameDown.form1.POPNameCol.value = parent.RightFrameDown.form1.OrgNameInfo.value +"^"+  parent.RightFrameDown.form1.PersNameInfo.value;
	}
	
	function ChoiceAllPer(obj)
    {
        var iPersNum = form1.PersCount.value;
        if(obj.checked)
        {           
           for(i=0;i<iPersNum;i++)
            {
                if(iPersNum=="1")
                {
                    var PersValue = document.all.PersCK.value;
                    document.all.PersCK.checked = true;
                    //alert(PersValue);
                    IfChoicePer(PersValue,"1");
                }
                else
                {
                    var PersValue = document.all.PersCK[i].value;
                    document.all.PersCK[i].checked = true;
                    //alert(PersValue);
                    IfChoicePer(PersValue,"1");
                }
            }
        }
        else
        {
            for(i=0;i<iPersNum;i++)
            {
                if(iPersNum=="1")
                {
                    var PersValue = document.all.PersCK.value;
                    document.all.PersCK.checked = false;
                    IfChoicePer(PersValue,"0");                                         
                    //alert(PersValue);
                }
                else
                {
                    var PersValue = document.all.PersCK[i].value;
                    document.all.PersCK[i].checked = false;
                    IfChoicePer(PersValue,"0");
                    //alert(PersValue);
                }
            }
        }
    }
    
    
    function IfChoicePer(obj,type)
    {
//	    var sPersIDInfo   = parent.RightFrameDown.form1.POPIDCol.value;
//        var sPersNameInfo = parent.RightFrameDown.form1.POPNameCol.value;
//        
//        var aPersIDInfo   = sPersIDInfo.split('^');
//        var aPersNameInfo = sPersNameInfo.split('^');
//        var sBack = "";
//        if(aPersIDInfo.length >1)
//        {        
//            sBack = DelRepeatData(aPersIDInfo[1],aPersNameInfo[1],obj,type);
//        }
//        else
//        {
//            sBack = DelRepeatData("","",obj,type);
//        }

        var sPersIDInfo   = parent.RightFrameDown.form1.PersIDInfo.value;    
        var sPersNameInfo = parent.RightFrameDown.form1.PersNameInfo.value;
        
        var sBack = DelRepeatData(sPersIDInfo,sPersNameInfo,obj,type);
        var aBack = sBack.split('|');
        
        parent.RightFrameDown.form1.PersIDInfo.value   = aBack[0];
        parent.RightFrameDown.form1.POPIDCol.value     = parent.RightFrameDown.form1.OrgIDInfo.value +"^"+ aBack[0] ;
        
        parent.RightFrameDown.form1.PersNameInfo.value = aBack[1];
        parent.RightFrameDown.form1.POPNameCol.value   =  parent.RightFrameDown.form1.OrgNameInfo.value +"^"+ aBack[1] ; 
//      parent.RightFrameDown.form1.POPIDCol.value     = parent.RightFrameDown.form1.OrgIDInfo.value +"^"+ parent.RightFrameDown.form1.PersIDInfo.value;
//      parent.RightFrameDown.form1.POPNameCol.value   = parent.RightFrameDown.form1.OrgNameInfo.value +"^"+  parent.RightFrameDown.form1.PersNameInfo.value;
	}
	
	
	//选择部门
	
	function ChoiceOrg(obj)
    {
        var sPersIDInfo   = parent.RightFrameDown.form1.OrgIDInfo.value;    
        var sPersNameInfo = parent.RightFrameDown.form1.OrgNameInfo.value;
        
        var sBack = "";
        if(obj.checked)
        {
           sBack = DelRepeatData(sPersIDInfo,sPersNameInfo,obj.value,"1");
        }
        else
        {
           sBack = DelRepeatData(sPersIDInfo,sPersNameInfo,obj.value,"0");
        }
        
        var aBack = sBack.split('|');
        
        parent.RightFrameDown.form1.OrgIDInfo.value    = aBack[0];
        parent.RightFrameDown.form1.POPIDCol.value     = aBack[0] +"^"+ parent.RightFrameDown.form1.PersIDInfo.value ;
        
        parent.RightFrameDown.form1.OrgNameInfo.value = aBack[1];
        parent.RightFrameDown.form1.POPNameCol.value   = aBack[1] +"^"+ parent.RightFrameDown.form1.PersNameInfo.value ; 
    
//        var sDelOrgID   ="";  //部门ID 
//        var sDelOrgID2   ="";  //部门ID 
//	    var sDelOrgName = "";  //部门名称
//	    var sDelOrgName2 = "";  //部门名称
//	    
//	    var aOrg = obj.value.split(',');
//	    
//	    if(parent.RightFrameDown.form1.OrgIDInfo.value != "")
//        {
//            var astr = parent.RightFrameDown.form1.OrgIDInfo.value.split(',');
//            if(astr.length=="1")
//            {
//                var sDelOrgID   = aOrg[0];        
//	            var sDelOrgName = aOrg[1];
//            }
//            else
//            {
//                var sDelOrgID   = "," + aOrg[0];
//	            var sDelOrgID2   = aOrg[0] + ",";
//	            var sDelOrgName = "," + aOrg[1];
//	            var sDelOrgName2 = aOrg[1] + ",";
//	        }
//	        
//            var sOrgID   = "," + aOrg[0];  //部门ID 
//	        var sOrgName = "," + aOrg[1];  //部门名称
//        }
//        else
//        {
//            var sOrgID   = aOrg[0];  //部门ID 
//	        var sOrgName = aOrg[1];  //部门名称
//	        
//	        var sDelOrgID   = aOrg[0];
//	        var sDelOrgName = aOrg[1];
//        }
//        
//        if(obj.checked)
//        {
//           parent.RightFrameDown.form1.OrgIDInfo.value = parent.RightFrameDown.form1.OrgIDInfo.value.replace(sDelOrgID,"");
//           parent.RightFrameDown.form1.OrgIDInfo.value = parent.RightFrameDown.form1.OrgIDInfo.value.replace(sDelOrgID2,"");
//           parent.RightFrameDown.form1.OrgIDInfo.value = parent.RightFrameDown.form1.OrgIDInfo.value + sOrgID ;
//           parent.RightFrameDown.form1.OrgNameInfo.value = parent.RightFrameDown.form1.OrgNameInfo.value.replace(sDelOrgName,"");
//           parent.RightFrameDown.form1.OrgNameInfo.value = parent.RightFrameDown.form1.OrgNameInfo.value.replace(sDelOrgName2,"");
//           parent.RightFrameDown.form1.OrgNameInfo.value = parent.RightFrameDown.form1.OrgNameInfo.value + sOrgName ;
//        }
//        else
//        {
//            parent.RightFrameDown.form1.OrgIDInfo.value = parent.RightFrameDown.form1.OrgIDInfo.value.replace(sDelOrgID,"");
//            parent.RightFrameDown.form1.OrgIDInfo.value = parent.RightFrameDown.form1.OrgIDInfo.value.replace(sDelOrgID2,"");
//            parent.RightFrameDown.form1.OrgNameInfo.value = parent.RightFrameDown.form1.OrgNameInfo.value.replace(sDelOrgName,"");
//            parent.RightFrameDown.form1.OrgNameInfo.value = parent.RightFrameDown.form1.OrgNameInfo.value.replace(sDelOrgName2,"");
//        }
//        parent.RightFrameDown.form1.POPIDCol.value = parent.RightFrameDown.form1.OrgIDInfo.value +"^"+ parent.RightFrameDown.form1.PersIDInfo.value;
//        parent.RightFrameDown.form1.POPNameCol.value = parent.RightFrameDown.form1.OrgNameInfo.value +"^"+  parent.RightFrameDown.form1.PersNameInfo.value;
        //alert(parent.RightFrameDown.form1.OrgIDInfo.value);
        //alert(parent.RightFrameDown.form1.OrgNameInfo.value);
        //parent.form1.cseat_no.value = form1.DelTicketInfo.value;
	}
	
	//去掉重复的数据sData:字符串 sID:比较的ID
   // function  DelRepeatData(//去掉重复的数据sData:字符串 sID:比较的ID
    function  DelRepeatData(sID,sName,sObj,Ifchecked)
    {
       var sBack="";
       var sIDCol="";
       var sNameCol="";
       var aObj = sObj.split(',');       
       if(sID != "")
       {
           var aryName = sName.split(',');
           var ary = sID.split(',');
           var iary = ary.length;
           for(x=0;x<ary.length;x++)
           {
               if(ary[x] !=aObj[0])
               {
                   if(x!=0 && sIDCol !="")
                   {
                       sIDCol   = sIDCol + ",";
                       sNameCol = sNameCol + ",";
                   }
                   sIDCol   = sIDCol + ary[x];
                   sNameCol = sNameCol + aryName[x];                   
               }               
           }
       }
       if(Ifchecked == "1")
       {
           if(sIDCol == "")
           {
               sIDCol   = sIDCol   + aObj[0];
               sNameCol = sNameCol + aObj[1];
           }
           else
           {
               sIDCol   = sIDCol   + ","+ aObj[0];
               sNameCol = sNameCol + ","+ aObj[1];
           }
       }
       
       sBack    = sIDCol +"|"+ sNameCol ;
       return sBack
    }
//    ,sName,sObj,Ifchecked)
//    {
//       var sBack="";
//       var sIDCol="";
//       var sNameCol="";
//       var aObj = sObj.split(',');       
//       if(sID != "")
//       {
//           var aryName = sName.split(',');
//           var ary = sID.split(',');
//           var iary = ary.length;
//           for(x=0;x<ary.length;x++)
//           {
//               if(ary[x] !=aObj[0])
//               {
//                   if(x!=0 && sIDCol !="")
//                   {
//                       sIDCol   = sIDCol + ",";
//                       sNameCol = sNameCol + ",";
//                   }
//                   sIDCol   = sIDCol + ary[x];
//                   sNameCol = sNameCol + aryName[x];                   
//               }               
//           }
//       }
//       if(Ifchecked == "1")
//       {
//           if(sIDCol == "")
//           {
//               sIDCol   = sIDCol   + aObj[0];
//               sNameCol = sNameCol + aObj[1];
//           }
//           else
//           {
//               sIDCol   = sIDCol   + ","+ aObj[0];
//               sNameCol = sNameCol + ","+ aObj[1];
//           }
//       }
//       
//       sBack    = sIDCol +"|"+ sNameCol ;
//       return sBack
//    }
    
  </script>
</head>
<body>
    <form id="form1" runat="server">    
    <table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
      <tr style ="height :30px;">
       <td><asp:Label ID="OrgName" runat ="server" ></asp:Label></td>
    </tr>
    <tr>
      <td>
        <table width="100%" border="0" align="center" cellpadding="0" cellspacing="0" class="table">
          <%=sHtml%>
        </table>   
      </td>
    </tr>
    </table>
    <input type="hidden" id="PersCount" runat ="server"  />
    <input type="hidden" id="OrgCount" runat ="server"  />
    </form>
    
    <script language ="javascript" type ="text/javascript" >
        //parent.RightFrameDown.form1.PersIDInfo.value =  parent.RightFrameDown.form1.POPIDCol.value ;  //人员ID初始化
        //parent.RightFrameDown.form1.PersNameInfo.value =  parent.RightFrameDown.form1.POPNameCol.value ;  //人员Name初始化
        //debugger;
    var sPersIDCol = "";  //人员ID的集合.
    var sOrgIDCol = "";   //部门ID的集合
    var aPOPIDCol = "";
    var aPOPNameCol = "";
    var err;
    try
    {
        aPOPIDCol = parent.RightFrameDown.form1.POPIDCol.value.split('^');
        aPOPNameCol = parent.RightFrameDown.form1.POPNameCol.value.split('^');
    }
    catch(err)
    {
        aPOPIDCol ="";  
        aPOPNameCol = "";      
    }    
    //var aPOPIDCol = parent.RightFrameDown.form1.POPIDCol.value.split('^');
    //var aPOPNameCol = parent.RightFrameDown.form1.POPNameCol.value.split('^');
    if(aPOPIDCol.length == "2")
    {
//        parent.RightFrameDown.form1.PersIDInfo.value =  aPOPIDCol[2] ;  //人员ID初始化
//        parent.RightFrameDown.form1.OrgIDInfo.value =   aPOPIDCol[1] ;  //部门ID初始化
//        
//        parent.RightFrameDown.form1.PersNameInfo.value =  aPOPNameCol[1] ;  //人员Name初始化
//        parent.RightFrameDown.form1.OrgNameInfo.value =   aPOPNameCol[0] ;  //部门Name初始化
        parent.RightFrameDown.form1.PersIDInfo.value =  aPOPIDCol[1] ;  //人员ID初始化
        parent.RightFrameDown.form1.OrgIDInfo.value =   aPOPIDCol[0] ;  //部门ID初始化
        
        parent.RightFrameDown.form1.PersNameInfo.value =  aPOPNameCol[1] ;  //人员Name初始化
        parent.RightFrameDown.form1.OrgNameInfo.value =   aPOPNameCol[0] ;  //部门Name初始化

        
        //debugger;
        var iPersNum = form1.PersCount.value*1;
        var iOrgNum = form1.OrgCount.value*1;
        
        //人员ID的赋值
        for(i=0;i<iPersNum;i++)
        {
            if(iPersNum=="1")
            {
                var PersValue = document.all.PersCK.value;
                var PersAry = PersValue.split(',');
                
                var aPersID = aPOPIDCol[1].split(',');
                var iPersID = aPersID.length;
                for(k=0;k<iPersID;k++)
                {
                    if(aPersID[k]==PersAry[0])
                    {
                       document.all.PersCK.checked = true;
                       break;
                    }
                }
            }
            else
            {
                var PersValue = document.all.PersCK[i].value;
                var PersAry = PersValue.split(',');
                
                var aPersID = aPOPIDCol[1].split(',');
                var iPersID = aPersID.length;
                for(k=0;k<iPersID;k++)
                {
                    if(aPersID[k]==PersAry[0])
                    {
                       document.all.PersCK[i].checked = true;
                       break;
                    }
                }
            }
        }
        
        //部门ID的赋值

        if(iOrgNum=="1")
        {
            var PersValue = document.all.OrgCK.value;
            var PersAry = PersValue.split(',');
            
            var aPersID = aPOPIDCol[0].split(',');
            var iPersID = aPersID.length;
            for(k=0;k<iPersID;k++)
            {
                if(aPersID[k]==PersAry[0])
                {
                   document.all.OrgCK.checked = true;
                   break;
                }
            }
        }
          
    }
     </script>
</body>
</html>
